#ifndef __SOFT_TIMER_H_
#define __SOFT_TIMER_H_

#include "common_def.h"
#include "timer_b.h"

// soft timer is a wrapper over timer b.
// the time unit is still tick (1/32768 second).
// 8 individual timers can be set.
// the maximum interval of a timer is 2 (65536/32768) seconds.

#define TIMER_FLAG_PERIODIC   BIT0
#define TIMER_FLAG_REALTIME   BIT1

#define TIMER_COUNT 8

// some pre-defined timers
#define TIMER_ID_KICK_WATCHDOG          0
#define TIMER_ID_FLASH_LED              1
#define TIMER_ID_COLLECT_ACC            2
#define TIMER_ID_SECOND                 3
#define TIMER_ID_VOLTAGE_DELAY          4
// 2 for test
#define TIMER_ID_COLLECT_GT             5
#define TIMER_ID_WAIT_ACK               6
#define TIMER_ID_SECOND2                7

#define TIMER_INTERVAL_KICK_WATCHDOG    16384
#define TIMER_INTERVAL_FLASH_LED        32768
#define TIMER_INTERVAL_SECOND           32767
#define TIMER_INTERVAL_SECOND1          6553
#define TIMER_INTERVAL_SECOND2          29550
#define TIMER_INTERVAL_VOLTAGE_DELAY    1500  // about 50 ms
#define TIMER_INTERVAL_SEND_PACKET            32768

void soft_timer_init(void);
void soft_timer_start(uint8 index,
                      uint32 interval,
                      uint8 flags,
                      TIMERB_TASK_T task);
void soft_timer_stop(uint8 index);

void soft_timer_check(void);

uint32 timer_tick_to_ms(uint32 tick);
uint32 timer_ms_to_tick(uint32 ms);

void soft_timer_dump(void);

#endif // __SOFT_TIMER_H_
